<template>
	
	<!-- <div @touchmove.stop.prevent="moveHandle"> 样式
		<u-popup :show="show" mode="center" zIndex='99' duration="50">
			<view class="box-tk" v-if="list.length>0">
				<scroll-view scroll-y="true" v-if="list.length>0"
					:class="['box-xis',list.length > 3 ? 'box-aigicon':'']" @touchmove.stop />
					<view :class="['xis-title',list.length > 3 ? 'xis-title-aigicon':'']" v-text="list[0].remark" style="white-space:pre-wrap;"></view>
					<view class="box-img"></view>
					<view class="xis-hend" :class="[list.length>1 ? 'xis-avicon' :'']"
						<u-radio-group v-model="value" placement="row" activeColor="#7AD9DF !important"
							inactiveColor="#B0E9EC  !important">
							<u-radio :customStyle="{padding: '10px 0'}" v-for="(item, index) in radiolist" :key="index"
								:label="item.name" :name="item.name" @change="radioChange(item.id)"
								:class="value==item.name?'clao':'clat'">
							</u-radio>
						</u-radio-group>
						<view class="xis-yuanyin" v-if="yuanyinValue">
							<Select class="SelectList" :disabled="false" v-model="examinationTypeIndex"
								:options="teshuarray" @change="Selectchange"></Select>
							<u-textarea class="box-text" placeholder="请输入原因" maxlength="-1" v-model="yuanyin2"
								confirmType="done" :disabled="textBled"></u-textarea>
						</view>
					</view>
				</scroll-view>
				<view class="tk-heard" v-if="list">
					<u-button type="primary" style="margin-right: 10px;" text="确认" class="btn" color="#82ECC3"
						@tap="StopImplement"></u-button>
					<u-button type="primary" text="取消" class="btn" color="#FF6E91" @tap="cancel"></u-button>
				</view>
			</view>
		</u-popup>
	</div> -->
	
	<uni-popup ref="popup" type="dialog" :mask-click="false">
		<view class="box-tk" v-if="list.length>0">
			<scroll-view scroll-y="true" v-if="list.length>0" :class="['box-xis',list.length > 3 ? 'box-aigicon':'']" @touchmove.stop >
				<view :class="['xis-title',list.length > 3 ? 'xis-title-aigicon':'']" v-text="list[0].remark" style="white-space:pre-wrap;"></view>
				<view class="box-img"></view>
				<view class="xis-hend" :class="[list.length>1 ? 'xis-avicon' :'']">
					<u-radio-group v-model="value" placement="row" activeColor="#7AD9DF !important"
						inactiveColor="#B0E9EC  !important">
						<u-radio :customStyle="{padding: '10px 0'}" v-for="(item, index) in radiolist" :key="index"
							:label="item.name" :name="item.name" @change="radioChange(item.id)"
							:class="value==item.name?'clao':'clat'">
						</u-radio>
					</u-radio-group>
					<view class="xis-yuanyin" v-if="yuanyinValue">
						<Select class="SelectList" :disabled="false" v-model="examinationTypeIndex"
							:options="teshuarray" @change="Selectchange"></Select>
						<u-textarea class="box-text" placeholder="请输入原因" maxlength="-1" v-model="yuanyin2"
							confirmType="done" :disabled="textBled"></u-textarea>
					</view>
				</view>
			</scroll-view>
			<view class="tk-heard" v-if="list">
				<u-button type="primary" style="margin-right: 10px;" text="确认" class="btn" color="#82ECC3"
					@tap="StopImplement"></u-button>
				<u-button type="primary" text="取消" class="btn" color="#FF6E91" @tap="cancel"></u-button>
			</view>
		</view>
		
		</uni-popup>
</template>

<script>
	import {
		EmpInfo,
		EMR_Nursing_ScanPSaveOrder_NS1,
		Nur_orderdo_zhongduan,
		Nur_orderdo_huifu,
		Nur_orderdo_jieshu_V1
	} from "@/api/user.js"
	import Select from '@/pages/ListOfPatients/selevt.vue'
	import {
		mapMutations,
		mapState
	} from "vuex";
	export default {
		props: {
			show: {
				type: Boolean,
				default: false
			},
			reportObj: {
				type: Array
			},
			reportShow: {
				type: Boolean
			},
			radiolist: {
				type: Array
			},
			teshuarray: {
				type: Array
			},
			title: {
				type: String
			}
		},
		components: {
			Select
		},
		data() {
			return {
				// show2: true
				Lthegiht: '',
				value: '',
				value1: '',
				time: '',
				list: [],
				radioValue: '',
				yuanyin: '',
				placeholder: '',
				yuanyin2: '',
				yuanyinValue: false,
				examinationTypeIndex: 0,
				putong_ady: '',
				textBled: true
			}
		},
		computed: {
			...mapState('user', ["userInfo", "deleteObj", "scanningArray"]),
		},
		watch: {
			show: {
				handler(newval, oldval) {
					console.log(newval, 'newval');
					if (newval) {
						this.$refs.popup.open('center')
						if (this.radiolist.length > 0) {
							this.value = this.radiolist[0].name
							
						}
						this.list = this.reportObj
					}else{
						this.$refs.popup.close()
					}
				}
			}
		},
		mounted() {
			if(this.show){
				this.$refs.popup.open('center')
				if (this.radiolist.length > 0) {
					this.value = this.radiolist[0].name
					
				}
				this.list = this.reportObj
			}else{
				this.$refs.popup.close()
			}
		},
		methods: {
			cancel() {
				
			uni.showModal({
				title: '提示',
				content: '是否用药取消',
				success:  (res)=> {
					if (res.confirm) {
						this.yuanyinValue = false
						this.$emit('loopTion', false, this.reportObj, 'quxiao');
					} else if (res.cancel) {
						console.log('用户点击取消');
					}
				}
			});
				
				
				
				
			},
			async StopImplement() {
				if (this.title == '病人列表') {
					let stryuan = ''
					if (this.radioValue == '') {
						this.radioValue = 'end'
						// return
					}
					if (this.radioValue == 'mid' && this.putong_ady == 6 && this.yuanyin2.trim() == '') {
						uni.showToast({
							title: `您选择了：${this.radiolist[this.radiolist.length-1].name}\n请输入信息${this.radiolist[0].name}信息！`, //显示的文字
							duration: 2000, //显示多少时间，默认1500毫秒
							icon: "none", //自定义显示的图标，默认成功success，错误error,加载loading，不显示图标是none
							mask: true
						})
						return
					}
					if (this.putong_ady == 6) {
						if (this.yuanyin2.trim() == '') {
							uni.showToast({
								title: `您选择了：${this.teshuarray[this.putong_ady].label}\n请输入信息${this.teshuarray[this.putong_ady].label}信息！`, //显示的文字
								duration: 2000, //显示多少时间，默认1500毫秒
								icon: "none", //自定义显示的图标，默认成功success，错误error,加载loading，不显示图标是none
								mask: true
							})
							return;
						}
						stryuan = this.yuanyin2.toString().trim();
					} else {
						stryuan = this.yuanyin2.toString().trim();
					}
					if (this.list[0].exeflag == '1' && this.radioValue == 'start') {
						uni.showToast({
							title: '输液未中断不能恢复！', //显示的文字
							duration: 2000, //显示多少时间，默认1500毫秒
							icon: "none", //自定义显示的图标，默认成功success，错误error,加载loading，不显示图标是none
							mask: true
						})
						return;
					}
					await this.AdviceActionYuanyin(stryuan, this.list)
				} else {
					let stryuan = ''
					if (this.radioValue == '') {
						this.radioValue = 'end'
						// return
					}
					if (this.radioValue == 'mid' && this.putong_ady == 6 && this.yuanyin2.trim() == '') {
						uni.showToast({
							title: "您选择了未服药其他，请输入原因", //显示的文字
							duration: 2000, //显示多少时间，默认1500毫秒
							icon: "none", //自定义显示的图标，默认成功success，错误error,加载loading，不显示图标是none
							mask: true
						})
						return
					}
					if (this.radioValue == 'mid') {
						if (this.putong_ady == 6) {
							stryuan = this.yuanyin2.toString().trim();
						} else {
							stryuan = this.yuanyin2.toString().trim();
						}
					} else if (this.radioValue == 'end') {
						stryuan = "";
					} else {
						stryuan = "";
					}
					await this.zhixingData(stryuan, this.list)
				}
			},
			async zhixingData(stryuan, obj) {
				let user = uni.getStorageSync('userInfo')
				try {
					
					
					const promises =	obj.map(async item=>{
							let	result = await this.$http.EMR_Nursing_ScanPSaveOrder_NS1({
							HosKind: user.hoscode,
							sExemode: 'PDA扫描',
							mrn: item.mrn,
							stay: 'I',
							series: item.series,
							orderdordnarray: item.orderdordn,
							bedid: item.bedid,
							pname: item.pname,
							operdept: user.HosKind,
							operjp: user.sUserid,
							iMark: item.iMark,
							iautocharge: item.iautocharge,
							exeflag3: stryuan
						})
							return result
						})
						  const [res] = await Promise.all(promises);
					if (res[0].result == '1') {
						this.$emit('loopTion', false, this.list, 'queren');
						uni.showToast({
							title: "医嘱执行成功！", //显示的文字
							duration: 2000, //显示多少时间，默认1500毫秒
							icon: "none", //自定义显示的图标，默认成功success，错误error,加载loading，不显示图标是none
							
						})
						// return
					} else {
						uni.showToast({
							title: res[0].result, //显示的文字
							duration: 2000, //显示多少时间，默认1500毫秒
							icon: "none", //自定义显示的图标，默认成功success，错误error,加载loading，不显示图标是none
							
						})
						this.$emit('loopTion', false, this.list, 'shibai', res[0].result);
					}
				} catch (e) {
					uni.showToast({
						title: '执行异常！', //显示的文字
						duration: 2000, //显示多少时间，默认1500毫秒
						icon: "none", //自定义显示的图标，默认成功success，错误error,加载loading，不显示图标是none
					
					})
					//TODO handle the exception
				}
			},
			async AdviceActionYuanyin(stryuan, obj) {
				try {
					let sResult;
					let user = uni.getStorageSync('userInfo')
					if (this.radioValue == 'mid') {
						const data = {
							HosKind: user.hoscode,
							mrn: obj[0].mrn,
							series: obj[0].series,
							plandate: obj[0].plandate,
							setno: obj[0].setno,
							endmark: stryuan
						}
						sResult = await this.$http.Nur_orderdo_zhongduan(data)

					} else if (this.radioValue == 'start') {
						const data = {
							HosKind: user.hoscode,
							mrn: obj[0].mrn,
							series: obj[0].series,
							plandate: obj[0].plandate,
							setno: obj[0].setno,
						}
						sResult = await this.$http.Nur_orderdo_huifu(data)

					} else {
						const data = {
							HosKind: user.hoscode,
							mrn: obj[0].mrn,
							series: obj[0].series,
							plandate: obj[0].plandate,
							setno: obj[0].setno,
							dobarcode: obj[0].dobarcode,
							prtype: obj[0].prtype,
							operdept: user.HosKind,
							operjp: user.sUserid,
						}
						sResult = await this.$http.Nur_orderdo_jieshu_V1(data)
					}
					if (sResult[0].result == '1') {
						this.$emit('loopTion', false, this.list, 'queren');
						uni.showToast({
							title: '操作成功！', //显示的文字
							duration: 1000, //显示多少时间，默认1500毫秒
							icon: "success", //自定义显示的图标，默认成功success，错误error,加载loading，不显示图标是none
						
						})
					} else {
						uni.showToast({
							title: sResult[0].result, //显示的文字
							duration: 2000, //显示多少时间，默认1500毫秒
							icon: "error", //自定义显示的图标，默认成功success，错误error,加载loading，不显示图标是none
						
						})
					}
				} catch (e) {
					uni.showToast({
						title: '执行异常！', //显示的文字
						duration: 2000, //显示多少时间，默认1500毫秒
						icon: "error", //自定义显示的图标，默认成功success，错误error,加载loading，不显示图标是none
						mask: true
					})
					//TODO handle the exception
				}
			},
			radioChange(data) {
				this.radioValue = data
				if (data == 'mid') {
					this.list[0].yuanyin2 = this.yuanyin2
					this.yuanyinValue = true
					this.examinationTypeIndex = 0
					this.yuanyin2 = this.teshuarray[this.examinationTypeIndex].label
				} else {
					this.yuanyin2 = ''
					this.putong_ady = ''
					this.yuanyinValue = false
					this.textBled = false
				}
			},
			Selectchange(e) {
				this.putong_ady = e
				if (e == 6) {
					this.yuanyin2 = ''
					this.textBled = false
				} else {
					this.yuanyin2 = this.teshuarray[e].label
					this.textBled = true
				}
			},
			moveHandle() {}
		}
	}
</script>


<style scoped lang="scss">
	::v-deep .u-popup {
		.u-fade-enter-active {
			z-index: 99 !important;
		}
	}
	
	::v-deep.uni-popup{
			.uni-popup__wrapper{
				width: 100%;
				// padding: 40rpx;
				background-color: #fff !important;
			}
		}

	.xis-yuanyin {
		display: flex;
		align-items: center;
		height: 30px;
		margin: 0 6px;
		padding-bottom: 9px;

		.SelectList {
			width: 140px !important;
		}
	}

	 .box-tk {
	
		// width: 100%;
		padding: 0 20rpx;
		// height: 212rpx;
		// background: #FFFFFF;
		border-radius: 8rpx;
		position: relative;
		padding-bottom: 15rpx;

		.view1 {
			font-size: 36rpx;
			font-family: SourceHanSansCN-Medium, SourceHanSansCN;
			font-weight: 500;
			color: #487bf4;
			line-height: 40px;
			text-align: center;
			display: flex;
			justify-content: space-evenly;
			align-items: center;

			.view1-title {
				color: #333333;

			}
		}

		.box-xis {
			width: 100%;
			// height: 92%;
			background: #B0E9EC;
			margin: 20rpx auto 0;
			padding-bottom: 12rpx;
			position: relative;
			border-radius: 12rpx;
			z-index: 999;

			.uni-scroll-view {
				overflow: inherit !important;
			}

			.uni-scroll-view-content {
				width: 100% !important;
			}

			.box-img {
				position: absolute;
				right: 0;
				top: 0;
				width: 58px;
				height: 28px;
				background: url('../../static/img/coagulation.svg') no-repeat;
				background-size: 100% auto;
				box-shadow: 5px -3px 8px 0px #D4D9D9;
			}

			.xis-title {
				font-size: 16px;
				font-family: SourceHanSansCN-Normal, SourceHanSansCN;
				font-weight: 400;
				color: #ff0000;
				padding: 4rpx 18rpx;
				line-height: 28px;
				// height: 28px;
				width: 80%;
			}
			.xis-title-aigicon{
				height: calc(100% - 60px);
				overflow: scroll;
				margin-bottom: 10px;
			}
			.xis-hend {
				// width: 303px;
				width: 96%;
				// height: calc(100%);
				// height: 81%;
				margin: 0 auto;
				// height: 228px;
				background: #F6FEFF;
				border-radius: 6px;
				opacity: 0.95;

				text {
					font-size: 32rpx;
					font-family: SourceHanSansCN-Medium, SourceHanSansCN;
					font-weight: 500;
					color: #333333;
					line-height: 48rpx;
					text-align: justify;
					text-align-last: justify;
				}

			}
		}

		.tk-heard {
			display: flex;
			// height: calc(100% - 636rpx);
			align-items: center;
			margin: 16rpx auto 0;
			// padding: 0 40rpx;
		}
	}

	.box-aigicon {
		height: 320px;
	}

	::v-deep .u-radio__icon-wrap--circle {
		width: 26px !important;
		height: 26px !important;
		background-color: rgb(122, 217, 223) !important;
	}

	::v-deep .u-radio-group--row {
		justify-content: space-around;
	}

	.clao ::v-deep {
		.u-icon__icon {
			border-radius: 100%;
			background: #FEFF87;
			color: #FEFF87 !important;
			width: 13px !important;
			height: 13px !important;
			// font-size: 16px !important;
		}
	}

	.clat ::v-deep {
		.u-icon__icon {
			border-radius: 100%;
			background: #FFFFFF;
			// font-size: 16px !important;
			width: 13px !important;
			height: 13px !important;
		}
	}

	.box-text {
		padding: 7px !important;
	}

	.u-textarea::v-deep {
		.u-textarea__field {
			height: 100% !important;
		}

		.uni-textarea-wrapper {
			overflow: hidden !important;
		}
	}
	
	.tk-heard {
		display: flex;
	}
</style>
